// 组合模式
// export const passwordRule =
//   /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\W_]).{6,18}$/;
export const passwordRule = /^[0-9a-zA-Z!@#$%^&*]{6,18}$/;

import type { Rule } from "ant-design-vue/es/form";

/**
 * 验证密码
 * @param {*} value
 * @returns
 */
export function checkPassword(_rule: Rule, value: string) {
  if (!value) {
    return Promise.reject("请输入密码");
  } else if (!passwordRule.test(value)) {
    return Promise.reject("密码格式不正确");
  } else {
    return Promise.resolve();
  }
}

export function checkFormNumber(rule: Rule, value: string | number | any) {
  if (!value || value === "") {
    return Promise.reject("请输入金额");
  } else if (isNaN(value * 1)) {
    return Promise.reject("请输入数字");
  } else {
    return Promise.resolve();
  }
}

/**
 * 必填规则
 * @param { String } msg：错误描述
 * @returns
 */
export function validateRequired(trigger?: string, msg?: string) {
  let m: string = "请输入";
  if (trigger && (trigger === "change" || Array.isArray(trigger))) {
    m = "请选择";
  }
  return {
    required: true,
    message: m,
    trigger: ["change", "blur"],
  };
}
